package com.bytesizedhosting.api.android.darthcrap.screens;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;

import com.bytesizedhosting.api.android.darthcrap.Constants;
import com.bytesizedhosting.api.android.darthcrap.ExtendedActivity;
import com.bytesizedhosting.api.android.darthcrap.R;

public class FirstTimeScreen extends ExtendedActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
		SharedPreferences objSettings = this.getSharedPreferences(Constants.PREFS_FILE, Context.MODE_PRIVATE);
		
		if (objSettings.getBoolean(Constants.PREFS_SHOWN_FIRST_TIME_SCREEN, false)) {
			if (!objSettings.getBoolean(Constants.PREFS_SHOWN_STARTUP_MESSAGE, false)) {
	        	AlertDialog.Builder objBuilder = new AlertDialog.Builder(this);
	        	objBuilder.setTitle(R.string.loading_notice_title);
	        	objBuilder.setMessage(R.string.loading_notice_contents);
	        	objBuilder.setNeutralButton(R.string.generic_ok,new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface objDialog, int intID) {
						dismissScreen(Constants.PREFS_SHOWN_STARTUP_MESSAGE);
						objDialog.dismiss();
					}
				});
	        	objBuilder.create().show();
			}
			else {
				proceedToLoadingScreen();
			}
		}
		else {
			setContentView(R.layout.firsttime);
			findViewById(R.id.btnDismiss).setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View objView) {
					dismissScreen(Constants.PREFS_SHOWN_FIRST_TIME_SCREEN);
				}
			});
		}
    }
    
    private void dismissScreen(String strConstant) {
    	SharedPreferences.Editor objEditor = this.getSharedPreferences(Constants.PREFS_FILE, Context.MODE_PRIVATE).edit();
    	objEditor.putBoolean(strConstant, true);
    	objEditor.commit();
    	proceedToLoadingScreen();
    }
    
    private void proceedToLoadingScreen() {
    	switchTo(LoadingScreen.class, true, false);
    }
}